package sizeyunsuan;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;

/**
 * Created by 春旺 on 2017/5/14.
 */
public class Problem {
    public String Problem(int num1,int num2,int langue)throws IOException {
        String d="",Problem = "";
        int tr = 0,su = 0;
        if (num2>=2) {
            for (int i = 0; i < num1; i++) {
                for (int j = 0; j < num2; j++) {
                    //产生20及其以内的数字
                    Random a = new Random();
                    int p = a.nextInt(20)+1;
                    System.out.print(p+" ");
                    Problem = Problem + p ;
                    Problem = Problem + " ";
                    //产生运算符

                    String peo[] = {"+", "-", "*", "/"};
                    //最后一个数字之后没有运算符。
                    int p2 = a.nextInt(4);
                    if (j < num2 - 1) {
                        System.out.print(peo[p2] + " ");
                        Problem = Problem + peo[p2] ;
                        Problem = Problem + " ";
                    }

                }
                Calculater Pr = new Calculater();

                 d = Problem;
                 Pr.calc(d);
            FileWriter fm = new FileWriter("problem.txt");
                BufferedWriter bufferedWriter = new BufferedWriter(fm);
                bufferedWriter.write(d);
                bufferedWriter.newLine();
                bufferedWriter.flush();
                Problem = "";
                Scanner scan2 = new Scanner(System.in);
                if (langue ==1)
                    System.out.println("输入答案：");
                else if (langue== 2)
                    System.out.println("輸入答案：");
                else
                    System.out.println("Input answer:");

                String answer = scan2.nextLine();

                Judge judge = new Judge();
                judge.judge(answer,tr,su,langue);


            }
            return d;
        }
        else {
            if (langue ==1)
                System.out.println("输入有误：");
            else if (langue== 2)
                System.out.println("輸入有誤：");
            else
                System.out.println("Input error:");

            return "输入有误";
        }

    }

}